<template>
	<!-- 手工出库单 -->
	<view>
		<view class="card-wrapper">
			<!-- 主表 -->
			<view class="radius shadow shadow-lg bg-white padding-sm light bg-blue">
				
				<view class="flex flex-wrap padding-t-b">
						<view class="basis-xs">
							集团:
						</view>
						<view class="basis-xl text-black solid-bottom position-r" :class="activeLineIndex == 1 ? 'solid-bottom-blue' :'' " >
							<input class="wc-input" type="text" disabled  :value="mainOrder.GROUPNAME" placeholder=""/>
						</view>
					</view>
					<view class="flex flex-wrap padding-t-b">
						<view class="basis-xs">
							组织:
						</view>
						<view class="basis-xl text-black solid-bottom position-r" :class="activeLineIndex == 2 ? 'solid-bottom-blue' :'' " @tap="activeIndexM(2,'BA_ORGANIZE')">
							<!-- {{ mainOrder.ORGNAME || '' }} -->
							<input class="wc-input "   name="STORENAME" type="text" disabled :value="mainOrder.ORGNAME" placeholder="请选择"/>
							<view class="basis-xs text-right position-a down-arrow-btn " >
								<text class="cuIcon-triangledownfill text-xxl text-bold" :class="activeLineIndex == 2 ? 'text-blue' :'' "></text>
							</view>
						</view>
					</view>
					<view class="flex flex-wrap padding-t-b">
						<view class="basis-xs">
							部门:
						</view>
						<view class="basis-xl text-black solid-bottom position-r" :class="activeLineIndex == 3 ? 'solid-bottom-blue' :'' " @tap="activeIndexM(3,'BA_DEPARTMENT')">
							<input class="wc-input " disabled name="STORENAME" type="text"  :value="mainOrder.DEPTNAME" placeholder="请选择"/>
							<view class="basis-xs text-right position-a down-arrow-btn " >
								<text class="cuIcon-triangledownfill text-xxl text-bold" :class="activeLineIndex == 3 ? 'text-blue' :'' "></text>
							</view>
						</view>
					</view>
					
					<view class="flex flex-wrap padding-t-b">
						<view class="basis-xs">
							申请人:
						</view>
						<!-- @tap="activeIndexM(5,'BA_USER')" -->
						<view class="basis-xl text-black solid-bottom position-r" :class="activeLineIndex == 5 ? 'solid-bottom-blue' :'' " >
							<input class="wc-input width60" disabled type="text"  :value="mainOrder.APPLYER" placeholder="请选择"/>
						</view>
					</view>
					
					<view class="flex flex-wrap margin-top">
						<view class="basis-xs ">
							出库类型<span class="text-red">*</span>
						</view>
						<view class="basis-xl solid-bottom  text-black">
							<picker @change="bindPickerChange($event,'1')" :value="outTypeIndex" :range="outType"
								:range-key="'ItemName'" class="picker-wrap">
								<view> {{ $utils.getExNumName(outType,mainOrder.OUTTYPE) || '请选择' }} </view>
								<text class="dicon diconxiangxiazhankai position-a down-arrow"></text>
							</picker>
						</view>
					</view>
					
					<view class="flex flex-wrap margin-top" v-if="mainOrder.OUTTYPE ==1 || mainOrder.OUTTYPE == 2  ">
						<view class="basis-xs">
							所属产品<span class="text-red" v-if="mainOrder.PK_GROUP != 'TS.10' ">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexPRO('pp')">
							<input class="wc-input " disabled type="text" :value="mainOrder.PRODUCTNAME" placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>
					
					<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs">
							在建工程<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(1,'在建工程')">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.ZJGCNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>
					
					<view class="flex flex-wrap margin-top" v-if="mainOrder.OUTTYPE ==1 || mainOrder.OUTTYPE == 2 || mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs">
							研发工程<span class="text-red"v-if="mainOrder.PK_GROUP != 'TS.10' " >*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(2,'研发工程')">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.YFGCNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>
					
					<!-- <view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs ">
							是否资产<span class="text-red">*</span>
						</view>
						<view class="basis-xl solid-bottom  text-black radio-wrap">
							<radio-group @change="radioChange">
								<label class="radio">
									<radio value="1"  />是
								</label>
								<label class="radio">
									<radio value="0" checked="true" />否
								</label>
							</radio-group>
						</view>
					</view>
					
					<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs">
							资产<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(6,'资产')">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.MEANSNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>
					
					<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs">
							维修日期<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @click="dateEvent('NEXTPAIRDATE','M')">
							{{ mainOrder.NEXTPAIRDATE }}
						</view>
					</view> -->
					
					<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs">
							单车核算<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(3,'单车核算')">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.DCHSNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>
					
					<view class="flex flex-wrap margin-top" v-if=" mainOrder.OUTTYPE ==5 ">
						<view class="basis-xs">
							核算分类<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(4,'核算分类')">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.HSFLNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>
					
					
					<view class="flex flex-wrap margin-top"
						v-if="outType,mainOrder.OUTTYPE !=3 ||  outType,mainOrder.OUTTYPE !=4">
						<view class="basis-xs">
							业务类型<span class="text-red" v-if="mainOrder.PK_GROUP != 'TS.10' ">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(5,'业务类型')">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="mainOrder.YWLXNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>
					
					<view class="flex flex-wrap padding-t-b">
						<view class="basis-xs">
							备注:
						</view>
						<view class="basis-xl text-black solid-bottom" :class="isActiveNote? 'solid-bottom-blue' :'' ">
							<input @focus="activeNote" @blur="getNote" class="wc-input " type="text" v-model="mainOrder.VMEMO" placeholder="请输入"/>
						</view>
					</view>
				</view>
			<!-- 物资子表 -->
			
			<view class="radius shadow shadow-lg bg-white padding-sm margin-top sub-table" 
			v-for="(item,index) in checkData" :key="index">
				<view class="text-red delete-cicon" @click="removeEvent(index)">
					<i class='dicon'>&#xe937;</i>
				</view>
				
				<view class="flex flex-wrap margin-top" >
					<view class="basis-xs">
						物资状态 
					</view>
					
					<view class="basis-xl text-black position-r " @tap="openScan('STORE',index)">
						<input class="wc-input" :class="item.ISSURE?'text-green':'text-red'"  disabled style="width: 60%;" type="text"
						 :value="item.ISSURE?'已扫码确认':'未扫码确认请扫码确认' " />
						 
						<view class="basis-xs text-right position-a scan-btn " >
							<text class="cuIcon-scan text-xxl text-bold"></text>
						</view>
					</view>
				</view>
				
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						物资单号
					</view>
					<view class="basis-xl text-black">
						{{ item.PK_MATERIAL }}
					</view>
				</view>
				
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						物资名称
					</view>
					<view class="basis-xl text-black">
						{{ item.MATERIALNAME }} 
					</view>
				</view>
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						规格型号
					</view>
					<view class="basis-xl text-black">
						{{ item.MATSPEC  || '' }}
					</view>
				</view>
				
				<view class="" v-if=" mainOrder.OUTTYPE ==6 ">
					<view class="flex flex-wrap margin-top">
						<view class="basis-xs">
							材质
						</view>
						<view class="basis-xl text-black">
							{{ item.MATQULITY }}
						</view>
					</view>
					<view class="flex flex-wrap margin-top">
						<view class="basis-xs">
							产地
						</view>
						<view class="basis-xl text-black">
							{{ item.PRODUCTAREA || '' }}
						</view>
					</view>
					<view class="flex flex-wrap margin-top">
						<view class="basis-xs">
							货主
						</view>
						<view class="basis-xl text-black">
							{{ item.SHIPER || '' }}
						</view>
					</view>
					<view class="flex flex-wrap margin-top">
						<view class="basis-xs">
							重量
						</view>
						<view class="basis-xl text-black">
							{{ item.WEIGHTNUM || '' }} {{ item.WEIGHTUNIT || ''  }}
						</view>
					</view>
				</view>
				
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						库存总量
					</view>
					<view class="basis-xl text-black">
						{{ item.TOTALNUM  || '' }}/{{ item.UNIT  || '' }}
					</view>
				</view>
				
				<view class="flex flex-wrap margin-top" 
					v-for="(itemS,indexS) in $utils.mapSattionName(item.VBDEF18)" :key="indexS">
					<view class="basis-xs">
						{{indexS+1}}号货位
					</view>
					<view class="basis-xl text-black">
						{{ itemS.STATIONNAME || '' }}/{{ itemS.KCNUM }} {{ item.UNIT }}
					</view>
				</view>
								
				<view class="flex flex-wrap margin-top line-height-30 ">
					<view class="basis-xs ">
						出库数量<span class="text-red">*</span>
					</view>
					<view class="basis-xl solid-bottom  sub-table-input" >
						<!-- @blur="getRecommendM($event,index)" -->
						
						<input class="wc-input" v-model="item.NNUM" type="number" 
						 placeholder="请输入出库数量"/>
					</view>
				</view>
				
				<!-- 子表维护是否资产 -->
				<view class="" v-if="mainOrder.OUTTYPE ==5">
					<view class="flex flex-wrap margin-top line-height-30 ">
						<view class="basis-xs ">
							是否资产<span class="text-red">*</span>
						</view>
						<view class="basis-xl solid-bottom  text-black radio-wrap">
							<radio-group @change="radioChange($event, index)">
								<label class="radio">
									<radio value="1" :checked="item.ISMEANS==1" />是
								</label>
								<label class="radio">
									<radio value="0" :checked="item.ISMEANS==0" />否
								</label>
							</radio-group>
						</view>
					</view>
					<view class="flex flex-wrap margin-top line-height-30 ">
						<view class="basis-xs">
							资产<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @tap="activeIndexGS(6,'资产' , index)">
							<input class="wc-input " disabled name="STORENAME" type="text" :value="item.MEANSNAME"
								placeholder="请选择" />
							<view class="basis-xs text-right position-a down-arrow-btn ">
								<text class="cuIcon-triangledownfill text-xxl text-bold"></text>
							</view>
						</view>
					</view>
					<view class="flex flex-wrap margin-top line-height-30 ">
						<view class="basis-xs">
							维修日期<span class="text-red">*</span>
						</view>
						<view class="basis-xl text-black solid-bottom position-r" @click="dateEvent('NEXTPAIRDATE', index )">
							{{ item.NEXTPAIRDATE }}
						</view>
					</view>	
				</view>
				
				<!-- <view class="flex flex-wrap margin-top " >
					<view class="basis-xs ">
						推荐仓库
					</view>
					<view class="basis-xl text-black solid-bottom">
						{{ item.STORENAME }}
					</view>
				</view> -->
				
				<view class="flex flex-wrap margin-top ">
					<view class="basis-xs">
						推荐货位
					</view>
					<view class="basis-xl text-black solid-bottom">
						{{ item.STATIONNAME }}
					</view>
				</view>
				
				
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						设备信息
					</view>
					<view class="basis-xl text-black position-r solid-bottom" :class="isActiveStore? 'solid-bottom-blue' :'' ">
						<input class="wc-input" style="width: 60%;" name="EQUIPNAME" type="text" :value="item.EQUIPNAME" placeholder="请选择"
						 @tap="activeIndexM(index,'EQBOM',true)" disabled />
						<view class="basis-xs text-right position-a scan-btn" @tap="handelScan(index)">
							<text class="cuIcon-scan text-xxl text-bold"></text>
						</view>
					</view>
				</view>
				
				
				<view class="flex flex-wrap margin-top ">
					<view class="basis-xs">
						生产日期
					</view>
					<view class="basis-xl text-black solid-bottom" @click="dateEvent('FACTORYDATE',index)">
						{{ item.FACTORYDATE }} 
					</view>
				</view>
				
				<view class="flex flex-wrap margin-top line-height-30 " v-if="false">
					<view class="basis-xs ">
						物资用途<span class="text-red">*</span>
					</view>
					<view class="basis-xl solid-bottom  sub-table-input">
						<picker @change="bindPickerChange($event,index,'2')" 
						:value="item.myindex01" 
						:range="materUse"
						:range-key="'ItemName'" 
						class="picker-wrap">
							<view> {{ materUse[item.myindex01].ItemName || '请选择' }} </view>
							<text class="dicon diconxiangxiazhankai position-a down-arrow"></text>
						</picker>
					</view>
				</view>
				
				<view class="flex flex-wrap margin-top ">
					<view class="basis-xs">
						保质期
					</view>
					<view class="basis-xl text-black solid-bottom">
						<!-- {{ item.EXPDATE }} -->
						<input class="wc-input" v-model="item.EXPDATE" type="text" value="item.EXPDATE" placeholder="请输入保质期"/>
					</view>
				</view>
				
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						入库日期
					</view>
					<view class="basis-xl text-black" @click="dateEvent('INSTOCKDATE',index)">
						{{  item.INSTOCKDATE }}
					</view>
				</view>
				<view class="flex flex-wrap margin-top">
					<view class="basis-xs">
						图片上传
					</view>
					<view class="basis-xl text-black position-r solid-bottom">
						<image :src="item.OUTPHOTO" mode="" class="input-img" @tap="previewImage(index)"></image>
						<view class="basis-xs text-right position-a scan-btn "  @click="updateImg(index)">
							<text class="cuIcon-upload text-xxl text-bold"></text>
						</view>
					</view>
				</view>
				
				<view class="flex flex-wrap margin-top line-height-30 ">
					<view class="basis-xs ">
						备注
					</view>
					<view class="basis-xl solid-bottom  sub-table-input" >
						<input class="wc-input" v-model="item.VMEMO" placeholder="请输入备注"/>
					</view>
				</view>
				
			</view>
			
			
			<view class="">
				<button class="cu-btn block bg-blue margin-tb-sm lg" @click="submit">
					提交
				</button>
			</view>
		</view>
		
		<w-picker
			mode="dateTime" 
			startYear="2000" 
			endYear="2050"
			step="1"
			:defaultVal="[1,1,1,1,2,5]" 
			:current="true" 
			@confirm="onConfirm" 
			ref="dateTime" 
			themeColor="#f00"
		></w-picker>
		
	</view>
	
	
	
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import wPicker from "@/components/w-picker/w-picker.vue";
	import api from '@/common/api.js';
	import utils from '@/common/util.js';
	// var graceChecker = require("../../common/graceChecker.js");
	let query = {
			"category":"ST_INAPPLY",
			"page":1,
			"rows":"50",
			"sidx":"",
			"sord":"",
			"queryJson":{},
			"userId":"",
			"account":"admin"
	}
	let _self, dateTimekey, activeIndex, VMEMO,BILLFROM,activeType ; 
	export default{
		computed: mapState(['userInfo', 'baseUrl', 'materUse', 'checkData' ,'outType']),
		data(){
			return{
				outTypeIndex: 0,
				mainOrder:{
					"PK_GROUP": "",
					"GROUPNAME": "",
					"PK_ORG": "",
					"ORGNAME": "",
					"PK_DEPT": "",
					"DEPTNAME": "",
					"PK_APPLYER": "",
					"APPLYER": "",
					"PK_SUPPLY": "",
					"SUPPLYNAME": "",
					"PK_STORE": "",
					"STORENAME": "",
					"BILLFROM": 0,
					"VMEMO": "",
					"userId": "",
					"account": "",
					OUTTYPE: '1',
					OUTTYPENAME:'生产出库',
					PK_PRODUCT: '',
					PRODUCTNAME: '',
					PK_ZJGC: '',
					ZJGCNAME: '',
					PK_YFGC: '',
					YFGCNAME: '',
					PK_DCHS: '',
					DCHSNAME: '',
					PK_HSFL: '',
					HSFLNAME: '',
					YWLXNAME: '',
					PK_YWLX: '',
					ISMEANS: 0, // 是否资产
					PK_MEANS: '', // 资产编号
					MEANSNAME: '', // 资产名称
					NEXTPAIRDATE: '', // 资产维修日期
				},
				planList: [],
				isActiveNote:false,
				isActiveStore:false,
				activeSub:false, // 是否点击的物资列表的仓库，货位等选择控件
				mid:'',
				today:utils.getToDay(),
				dateTimekey:'',
				activeIndex:'',
				activeLineIndex: 0,
				label01: '单号', // 主表的第一个label BD_MATERIAL
				
			}
		},
		components: {
			wPicker
		},
		onLoad(p) {
			_self = this 
			this.initSetData();
			this.setOnceEvent()
			
			console.log( 777 , this.checkData );
		},
		
		onShow() {
			uni.$on('getSelectItem',function(data){
				// console.log(data);
				switch (activeType){
					case 'GROUP':
						_self.mainOrder.GROUPNAME = data.FullName
						_self.mainOrder.PK_GROUP = data.OrganizeId
						break;
					case 'BA_ORGANIZE':
						_self.mainOrder.ORGNAME = data.FullName
						_self.mainOrder.PK_ORG = data.OrganizeId
						break;
					case 'BA_DEPARTMENT':
						_self.mainOrder.DEPTNAME = data.FullName
						_self.mainOrder.PK_DEPT = data.OrganizeId
						break;
					case 'BD_SUPPLIER':
						_self.mainOrder.SUPPLYNAME = data.VNAME
						_self.mainOrder.PK_SUPPLY = data.BILLNO
						break;
					case 'BA_USER':
						_self.mainOrder.APPLYER = data.RealName
						_self.mainOrder.PK_APPLYER = data.UserId
						break;	
					case 'BD_STORE': // 仓库
						if(_self.activeSub){
							_self.checkData[_self.activeLineIndex].PK_STORE = data.BILLNO
							_self.checkData[_self.activeLineIndex].STORENAME = data.VNAME
						}else{
							_self.mainOrder.PK_STORE = data.BILLNO
							_self.mainOrder.STORENAME = data.VNAME
						}
						break;
					case 'BD_RACK': // 货位
						if(_self.activeSub){
							_self.checkData[_self.activeLineIndex].STATIONNAME = data.VNAME
							_self.checkData[_self.activeLineIndex].PK_STATION = data.BILLNO
						}
						break;
					case "EQBOM": // 设备
						_self.checkData[_self.activeLineIndex].EQUIPNAME = data.EQBOMNAME;
						_self.checkData[_self.activeLineIndex].PK_EQUIP = data.PK_EM_EQBOM;
						break;	
					default:
						break;
				}
			})	
		},
		onNavigationBarButtonTap(e) {
			e.index==0?this.addItem():_self.openScanMater()
		},
		onUnload(){
			uni.$off('getSelectItem')
			uni.$off('getSelectItemPro')
			uni.$off('getSelectItemGS')
		},
		methods:{
			...mapMutations(['deleteCheckData',"PushCheckData"]),
			
			setOnceEvent(){
				uni.$on('getSelectItemPro',res=>{
					this.mainOrder.PK_PRODUCT = res.VCODE
					this.mainOrder.PRODUCTNAME = res.VNAME
				})
				uni.$on('getSelectItemGS', res => {
					console.log(56,activeIndex, res);
					switch (res.TYPE) {
						case '1':
							this.mainOrder.PK_ZJGC = res.BILLNO
							this.mainOrder.ZJGCNAME = res.VNAME
							break;
						case '2':
							this.mainOrder.PK_YFGC = res.BILLNO
							this.mainOrder.YFGCNAME = res.VNAME
							break;
						case '3':
							this.mainOrder.PK_DCHS = res.BILLNO
							this.mainOrder.DCHSNAME = res.VNAME
							break;
						case '4':
							this.mainOrder.PK_HSFL = res.BILLNO
							this.mainOrder.HSFLNAME = res.VNAME
							break;
						case '5':
							this.mainOrder.PK_YWLX = res.BILLNO
							this.mainOrder.YWLXNAME = res.VNAME
							break;
						case '6':
							_self.checkData[activeIndex].PK_MEANS = res.ZCBH
							_self.checkData[activeIndex].MEANSNAME = res.ZCMC
							break;
					}
				})
			},
			
			getNote(e){
				VMEMO = e.target.value ;
			},
			
			// 初始化赋值
			initSetData(){
				query.userId = _self.userInfo.UserId
				query.account = _self.userInfo.Account
				_self.mainOrder.GROUPNAME = _self.userInfo.GROUPNAME || ''
				_self.mainOrder.PK_GROUP =  _self.userInfo.PK_GROUP
				_self.mainOrder.ORGNAME = _self.userInfo.ORGNAME
				_self.mainOrder.PK_ORG = _self.userInfo.ORGANIZEID
				_self.mainOrder.DEPTNAME = _self.userInfo.DEPTNAME
				_self.mainOrder.PK_DEPT = _self.userInfo.DEPARTMENTID
				_self.mainOrder.APPLYER = _self.userInfo.REALNAME
				_self.mainOrder.PK_APPLYER = _self.userInfo.UserId
				_self.mainOrder.OUTTYPE = 1
				_self.mainOrder.OUTTYPENAME = '生产出库'
				_self.mainOrder.userId = _self.userInfo.UserId
				_self.mainOrder.account = _self.userInfo.Account
				
				
			},
			
			onConfirm(val){
				if (activeIndex == 'M') {
					_self.mainOrder.NEXTPAIRDATE = val.result
				} else {
					this.checkData[activeIndex][dateTimekey] = val.result;
				}
			},
			dateEvent(id,index){
				dateTimekey = id ;
				activeIndex = index ;
				this.$refs.dateTime.show();
			},
			
			handelScan(i){
				this.$utils.openScanUtils( i,i, (res)=>{
					if(res.includes('TYPE:8')){
						let arr = res.split('|')
						_self.checkData[i].EQUIPNAME = arr[1]
						_self.checkData[i].PK_EQUIP = arr[2]
					}
				})
			},
			activeIndexM(i,t,activeSub){
				_self.activeLineIndex = i ; 
				activeType = t ;
				_self.activeSub = activeSub ;
				// console.log(78, _self.mainOrder.PK_ORG);
				if (t == "BA_ORGANIZE") {
					uni.navigateTo({
						url:'/pages/public/search?t='+t+ '&organizeId='+_self.mainOrder.PK_GROUP
					})
					return ;
				}
				uni.navigateTo({
					url:'/pages/public/search?t='+t
				})
			},
			
			activeIndexGS(i,Title , acindex){
				activeIndex = acindex
				let SSType = i   ;
				uni.navigateTo({
					url:'/pages/public/search-gs?t='+i+'&title='+Title+'&Btype='+ this.outType[this.outTypeIndex].ItemValue
				})
			},
			activeIndexPRO(i,t,activeSub){
				let SSType = i ;
				uni.navigateTo({
					url:'/pages/public/search-pro?t='+i
				})
			},
			
			activeNote(){
				_self.isActiveNote = true 
			},
			addItem(){
				uni.navigateBack({})
			},
			
			radioChange(v , i ){
				let val = v.detail.value
				_self.checkData[i].ISMEANS = val
			},
			
			bindPickerChange(e, i, t) {
				let val = e.target.value;
				if(t==2){
					_self.activeIndex = i;
					this.checkData[_self.activeIndex].myindex01 = val
					this.checkData[_self.activeIndex].PURPOSE = _self.materUse[val].ItemValue
					this.checkData[_self.activeIndex].MATERIALUSE = _self.materUse[val].ItemValue
				}else {
					_self.outTypeIndex = val
					_self.mainOrder.OUTTYPE = _self.outType[val].ItemValue
					_self.mainOrder.OUTTYPENAME = _self.outType[val].ItemName
					
					_self.mainOrder.PK_PRODUCT = ''
					_self.mainOrder.PRODUCTNAME = ''
					_self.mainOrder.PK_ZJGC = ''
					_self.mainOrder.ZJGCNAME = ''
					_self.mainOrder.PK_YFGC = ''
					_self.mainOrder.YFGCNAME = ''
					_self.mainOrder.PK_DCHS = ''
					_self.mainOrder.DCHSNAME = ''
					_self.mainOrder.PK_HSFL = ''
					_self.mainOrder.HSFLNAME = ''
					_self.mainOrder.YWLXNAME = ''
					_self.mainOrder.PK_YWLX = ''
				}
			},
			
			openScanMater() {
				let URL = this.userInfo.BaseURL + api.apiPublic.ScanCode;
				this.$utils.Scan(URL,item=>{
					
					item.FACTORYDATE = item.FACTORYDATE ? item.FACTORYDATE : "";
					item.EXPDATE = item.EXPDATE ? item.EXPDATE : "";
					item.INSTOCKDATE = item.INSTOCKDATE
					? item.INSTOCKDATE
					: _self.$utils.getToDay();
					item.TOTALNUM = item.TOTALNUM ? item.TOTALNUM : item.KCNUM;
					item.NNUM = 0;
					item.OUTPHOTO = item.OUTPHOTO ? item.OUTPHOTO : "";
					item.VBDEF20 = item.VBDEF20 ? item.VBDEF20 : 0;
					item.STORENAME = item.STORENAME ? item.STORENAME : "";
					item.PK_STORE = item.PK_STORE ? item.PK_STORE : "";
					item.STATIONNAME = item.STATIONNAME ? item.STATIONNAME : "";
					item.PK_STATION = item.PK_STATION ? item.PK_STATION : "";
					item.INPHOTO = item.INPHOTO ? item.INPHOTO : "";
					item.PURPOSE = item.PURPOSE ? item.PURPOSE : "";
					item.UNIT = item.UNIT ? item.UNIT : item.MINUNITNAME;
					item.myindex01 = item.myindex01 ? item.myindex01 : 0;

					console.log("MAP::",item);
					_self.PushCheckData(item)
				})
			},
			
			//  特殊处理天山 项目，根据扫码的货物查询物资
			
			
			
			
			// 获取推荐货位
			getRecommendM(e,i){
				let data = {
					userId : _self.userInfo.UserId,
					account : _self.userInfo.Account,
					PK_ORG: _self.userInfo.ORGANIZEID,
					NNUM : this.checkData[i].NNUM,
					PK_MATERIAL: this.checkData[i].PK_MATERIAL
				}
				let URL =  api.apiPublic.getRecommend ;
				// console.log(this.checkData[i]);
				console.log(55, '获取推荐货位' ,URL  );
				this.$utils.getRecommend(URL,data,res=>{
					
					console.log(88, '获取推荐货位' ,res  );
					
					let t = res[0];
					if(t.PK_MATERIAL !=this.checkData[i].PK_MATERIAL ){
						return this.tips('物资单号不匹配')
					}
					_self.checkData[i].PK_STORE = t.PK_STORE
					_self.checkData[i].STORENAME = t.STORENAME
					_self.checkData[i].STATIONNAME = t.STATIONNAME
					_self.checkData[i].PK_STATION = t.PK_STATION
					_self.checkData[i].BARCODE = t.BARCODE
				})
			},
			
			// 物资扫码确认
			openScan(id,index){
				let URL =  api.apiPublic.ScanCode;
				
				this.$utils.Scan(URL, data => {
					if(data.PK_GROUP  != '0102' && !data.PK_MATERIAL ){
						return _self.getMaterList(data , index )
					}
					console.log(999,   data.PK_MATERIAL, _self.checkData[index].PK_MATERIAL);
					if(data.PK_MATERIAL != _self.checkData[index].PK_MATERIAL ) {
						return _self.$utils.tips('扫描的物资单号和当前物资单号不匹配！');
					}
					_self.checkData[index].ISSURE = true 
					_self.checkData[index].PK_STORE = data.PK_STORE
					_self.checkData[index].STORENAME = data.STORENAME
					_self.checkData[index].STATIONNAME = data.STATIONNAME
					_self.checkData[index].PK_STATION = data.PK_STATION
					_self.checkData[index].BARCODE = data.BARCODE
					// _self.checkData[index].NNUM = data.NNUM || 0
				});
				
			},
			
			
			getMaterList( scanData , index ) {
				// console.log(999, scanData );
				let queryJson = { PK_STATION: scanData.PK_STATION  }
				let mQuery = JSON.parse(JSON.stringify(query));
				mQuery.category = 'ST_STOCKINFO'
				mQuery.queryJson =  JSON.stringify(queryJson);
				let URL =  api.apiPublic.getMaterList;
				this.axios({
					url: URL,
					data: mQuery ,
					isLoading: 1
				}).then(res => {
					let {
						IsSuccess,
						Result,
						Message
					} = res;
					let data = Result.rows[0] || null 
					_self.checkData[index].ISSURE = true
					_self.checkData[index].PK_STORE = scanData.PK_STORE
					_self.checkData[index].STORENAME = scanData.STORENAME
					_self.checkData[index].STATIONNAME = scanData.STATIONNAME
					_self.checkData[index].PK_STATION = scanData.PK_STATION
					_self.checkData[index].BARCODE = data.BARCODE
					console.log('mmmm' , res );
					if(data.PK_MATERIAL != _self.checkData[index].PK_MATERIAL ) {
						return _self.$utils.tips('扫描的物资单号和当前的物资单号不匹配！');
					}
					
				})
			},
			
			
			submit(){
				let data = { 
					..._self.mainOrder,
					"Detail": _self.checkData
				}
				for (let i = 0; i < this.checkData.length; i++) {
					let item = this.checkData[i], myIndex = i + 1;
					if(item.NNUM == '0' || item.NNUM == ''  ){
						return this.$utils.tips(`第${myIndex}个物资出库数量不能为空`)
					}else if (!item.ISSURE ) {
						this.$utils.tips('第' + myIndex + '个物资未进行扫码确认，请先扫物资二维码进行确认');
						return;
					}
				}
				data.Detail.forEach(item=>{
					if(!item.ISSURE){
						let MMDEF18 = this.$utils.mapSattionName(item.VBDEF18)[0] ;
						item.PK_STATION = MMDEF18.PK_STATION 
						item.BARCODE = MMDEF18.BARCODE
						item.PK_STORE = MMDEF18.PK_STORE
						// console.log(777, MMDEF18.PK_STATION , MMDEF18.BARCODE , item );
					}
				})
				console.log('submit::',data)
				let URL = api.apiPublic.SaveOutStore;
				// console.log(URL);
				this.axios({
					url:URL,
					data: data ,
					isLoading:1
				}).then(res=>{
					_self.$utils.tips('提交成功'+res.Message);
					utils.delayBack();
				})
			},
			// 图片上传
			updateImg(i){
				_self.activeIndex = i 
				_self.$utils.uploadImg(function(e){
					_self.checkData[_self.activeIndex].OUTPHOTO = e ;
				})
			},
			// 图片查看
			previewImage(i) {
				let imglist = this.planList[i].OUTPHOTO ;
				_self.$utils.previewImage(imglist);
			},
			
			removeEvent(i) {
				let d = this.checkData[i].myIndex + '' ;
				if(this.checkData.length==1){
					return this.$utils.tips('最后一项不可删除');
				}
				uni.$emit('deleteEvent',d)
				this.deleteCheckData(i);
			}
			
		}
	}
</script>

<style scoped>
	.card-wrapper{
		padding:26upx;
	}
	.card-wrapper .padding-sm{
		padding-top: 5rpx!important;
	}
	.line-height-30{
		line-height: 24px!important;
	}
	
	.sub-table-input{
		margin-top: 10upx;
	}
	.width60{
		width: 60%;
	}
	.down-arrow-btn{
		top: -20upx;
		right: 0upx;
		font-size: 40upx;
		padding: 10upx;
	}
	.add-btn-wrap{
		position: fixed;
		bottom: 100upx;
		right: 50upx;
	}
	.add-btn-wrap .cuIcon-add{
		font-size: 50upx;
	}
	
	.down-arrow{right: 26rpx;top: -10rpx;}
	.padding-t-b{
		padding: 20rpx 0;
	}
</style>
